package com.leetcode.双周赛.第48场;

/**
 * @author: xiaomi
 * @date: 2021/3/20
 * @description: 5693. 字符串中第二大的数字
 * https://leetcode-cn.com/contest/biweekly-contest-48/problems/second-largest-digit-in-a-string/
 */
public class A_5693_字符串中第二大的数字 {

    /**
     * 由于只考虑个位数字
     *
     * @param s
     * @return
     */
    public int secondHighest(String s) {
        char[] chars = s.toCharArray();
        int len = chars.length;
        //
        boolean[] recorder = new boolean[10];
        for (int i = 0; i < len; i++) {
            if (Character.isDigit(chars[i])) {
                recorder[chars[i] - 48] = true;
            }
        }
        int count = 0;
        for (int i = 9; i >= 0; i--) {
            if (recorder[i]) {
                if (count == 1) {
                    return i;
                }
                count++;
            }
        }
        return -1;
    }
}
